#!/usr/bin/python
# -*- coding: utf-8 -*-
# @version        : 1.0
# @Create Time    : 2024/9/6 11:11
# @File           : feature
# @IDE            : PyCharm
# @desc           : 描述
from datetime import datetime
from typing import List

from db.db_base import AuditModel
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy import String, DateTime, ForeignKey, Integer, Text


class DCASR(AuditModel):
    __tablename__ = "dc_check_asr"
    __table_args__ = ({'comment': 'ASR表单'})

    asr_no: Mapped[str] = mapped_column(String(20), unique=True, index=True, comment="ASR表单编号")
    part_no: Mapped[str] = mapped_column(String(40), comment="材料/零件图号")
    qar_no: Mapped[str] = mapped_column(String(20), comment="QAR编号")

    product_type: Mapped[str] = mapped_column(String(20), comment="产品型号(机型)")
    part_type: Mapped[str] = mapped_column(String(20), comment="材料类型, 例如零件、标准件、机载系统等")
    form_type: Mapped[str] = mapped_column(String(100), comment="表单类型，例如 SAMC 05-3(2012-06)")

    status: Mapped[str] = mapped_column(String(10), comment="表单状态，包括实验中、归档等")
    
    po_fo_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="PO/FO号")
    packing_sheet_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="装箱单号")
    mfg_shop_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="供应商/车间号")

    plan_remark: Mapped[str] = mapped_column(String(100), nullable=True, comment="计划备注")
    insp_remark: Mapped[str] = mapped_column(String(100), nullable=True, comment="检验备注")

    plan_user: Mapped[str] = mapped_column(String(50), nullable=True, comment="质量计划盖章, 工号、姓名、时间")
    insp_user: Mapped[str] = mapped_column(String(50), nullable=True, comment="质量检验盖章，工号、姓名、时间")

    ok_to_file: Mapped[str] = mapped_column(String(10), nullable=True, comment="归档")

    erratum_attachment: Mapped[str] = mapped_column(Text, nullable=True, comment="勘误说明附件")
    erratum_datetime: Mapped[datetime] = mapped_column(DateTime, nullable=True, comment="勘误时间")
    erratum_user: Mapped[str] = mapped_column(String(50), nullable=True, comment="勘误人员")

    contents: Mapped[List["DCASRContent"]] = relationship(back_populates='asr')
    insp_result: Mapped[str] = mapped_column(String(30), nullable=True, comment="检验结论")



class DCASRContent(AuditModel):
    __tablename__ = "dc_check_asr_content"
    __table_args__ = ({'comment': 'ASR检验内容表'})

    asr_id: Mapped[int] = mapped_column(
        Integer,
        ForeignKey("dc_check_asr.id", ondelete='CASCADE'),
        comment="ASR ID"
    )
    asr: Mapped[DCASR] = relationship(foreign_keys=asr_id, back_populates='contents')

    characteristic: Mapped[str] = mapped_column(String(40), comment="特征")
    dimension: Mapped[str] = mapped_column(String(40), comment="尺寸")
    irr: Mapped[str] = mapped_column(String(10), nullable=True, comment="初始可靠值")
    grade: Mapped[str] = mapped_column(String(10), nullable=True, comment="等级")
    count: Mapped[str] = mapped_column(String(20), nullable=True, comment="特征计数")

    insp_lot_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="检验批次号")
    lot_size: Mapped[int] = mapped_column(Integer, nullable=True, comment="一批数，即实际来料数量")
    
    sample_size: Mapped[int] = mapped_column(Integer, nullable=True, comment="样本数量")
    accept_qty: Mapped[int] = mapped_column(Integer, nullable=True, comment="接受数量，默认同样本数")
    reject_qty: Mapped[int] = mapped_column(Integer, nullable=True, comment="拒收数量")
    reject_tag_no: Mapped[str] = mapped_column(String(20), nullable=True, comment="拒收单号")

    insp_stamp: Mapped[str] = mapped_column(String(50), nullable=True, comment="检验人员刷卡，工号、姓名、时间")
